#include "threadtimer.h"
#include "timer.h"

static Timer g_time;

extern void callback(int signo)
{
	   g_time.add_time();
	   add_thread_time(g_time.get_time());
       g_time.reset();
}

extern uint32 get_time()
{
	g_time.get_time();
}

Timer::Timer()
{
	m_log = new logfile("timer");

	signal(SIGALRM, callback);
   
   m_value.it_value.tv_sec = 0;
   m_value.it_value.tv_usec = 1;
   m_value.it_interval.tv_sec = 0;
   m_value.it_interval.tv_usec = 1; 
   setitimer(ITIMER_REAL, &m_value, NULL); 
   m_time = 0;
}

Timer::~Timer()
{
	delete m_log;
}

void  Timer::reset()
{
   signal(SIGALRM, callback);
   
   m_value.it_value.tv_sec = 0;
   m_value.it_value.tv_usec = 1;
   m_value.it_interval.tv_sec = 0;
   m_value.it_interval.tv_usec = 1; 
   setitimer(ITIMER_REAL, &m_value, NULL); 
}

uint32 Timer::get_time()
{
	return m_time;
}

void Timer::add_time()
{
	m_time++;
}

